package baoxin.com.robotcoach.adapter;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import baoxin.com.robotcoach.R;
import baoxin.com.robotcoach.bean.StepTx;

public class TextAdapter extends RecyclerView.Adapter<TextAdapter.ViewHolder> {

    private List<StepTx> steps;
    private int txSize_normal = 24;
    private int txSize_current = 32;

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView step;

        public ViewHolder(View view) {
            super(view);
            step = view.findViewById(R.id.step_text);
        }
    }

    public TextAdapter(List<StepTx> steps){
        this.steps = steps;
    }

    @NonNull
    @Override
    public TextAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.step_text_item, parent, false);
        final ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull TextAdapter.ViewHolder holder, int position) {
        StepTx stepTx = steps.get(position);
   //     holder.step.setText(""+position+"."+stepTx.getText());
        holder.step.setText(stepTx.getText());
        if (stepTx.isCurrent()) {
            holder.step.setTextSize(txSize_current);
            holder.step.setTextColor(Color.parseColor("#97FCFF"));
        } else {
            holder.step.setTextSize(txSize_normal);
            holder.step.setTextColor(Color.parseColor("#ffffff"));

        }

    }

    @Override
    public int getItemCount() {
        return steps.size();
    }
}
